Regression from 2.6.36
Subsystems (2)
Hi,
we are successfully running several very busy web servers on 2.6.32.* and few days ago I decided to upgrade to 2.6.37 (mainly because of blkio cgroup). I installed 2.6.37.2 on one of the servers and very strange things started to happen with Apache web server.
We are using Apache with MPM-ITK ( http://mpm-itk.sesse.net/ ) so it is doing lots of 'fork' and lots of 'setuid'. I have also noticed that problem is happening only on very busy servers.
Everything is ok when Apache is started but as time is passing by, its 'root' processes (Apache processes running under root) are consuming more and more CPU. Finally, the whole server becames very unstable and Apache must be restarted. This is repeating until the load on web sites is much lower (usually on 22:00). Sometimes it takes 3 hours when restart is needed, sometimes only 1 hour (again, depends on load on web sites). Here is the graph of CPU utilization showing the problem (red color), Apache was REstarted at 8:11 and 9:35:
http://watchdog.sk/lkml/cpu-problem.png
Here is how it looks on htop:
http://watchdog.sk/lkml/htop.jpg
And finally here is how it looks with older kernels (yes, when i install older kernel, problem is gone), notice also that I/O wait is much lower and nicer (blue color):
http://watchdog.sk/lkml/cpu-ok.png
I was also strace-ing Apache processes which were doing problems, here it is:
http://watchdog.sk/lkml/strace.txt
I'm not 100% sure but I think that CPU was consumed on 'futex' lines.
I tried several kernel versions and find out that everything BEFORE 2.6.36 is NOT affected and everything AFTER 2.6.36 (included) is affected.
Versions which I tried and were NOT affected by this problem:
2.6.32.*
2.6.35.11
Versions which I tried and were affected by this problem:
2.6.36
2.6.36.4
2.6.37.2
2.6.37.3
2.6.38-rc8 (final version was not released yet)
All tests were made on vanilla kernels on Debian Lenny with this config:
http://watchdog.sk/lkml/config
Do you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Thank you !
azurit
Quoted 48 lines · azurIt
Hi,
we are successfully running several very busy web servers on 2.6.32.* and few days ago I decided to upgrade to 2.6.37 (mainly because of blkio cgroup). I installed 2.6.37.2 on one of the servers and very strange things started to happen with Apache web server.
We are using Apache with MPM-ITK ( http://mpm-itk.sesse.net/ ) so it is doing lots of 'fork' and lots of 'setuid'. I have also noticed that problem is happening only on very busy servers.
Everything is ok when Apache is started but as time is passing by, its 'root' processes (Apache processes running under root) are consuming more and more CPU. Finally, the whole server becames very unstable and Apache must be restarted. This is repeating until the load on web sites is much lower (usually on 22:00). Sometimes it takes 3 hours when restart is needed, sometimes only 1 hour (again, depends on load on web sites). Here is the graph of CPU utilization showing the problem (red color), Apache was REstarted at 8:11 and 9:35:
http://watchdog.sk/lkml/cpu-problem.pngHere is how it looks on htop:
http://watchdog.sk/lkml/htop.jpgAnd finally here is how it looks with older kernels (yes, when i install older kernel, problem is gone), notice also that I/O wait is much lower and nicer (blue color):
http://watchdog.sk/lkml/cpu-ok.pngI was also strace-ing Apache processes which were doing problems, here it is:
http://watchdog.sk/lkml/strace.txtI'm not 100% sure but I think that CPU was consumed on 'futex' lines.
I tried several kernel versions and find out that everything BEFORE 2.6.36 is NOT affected and everything AFTER 2.6.36 (included) is affected.
Versions which I tried and were NOT affected by this problem:
2.6.32.*
2.6.35.11Versions which I tried and were affected by this problem:
2.6.36
2.6.36.4
2.6.37.2
2.6.37.3
2.6.38-rc8 (final version was not released yet)
Quoted 7 lines
All tests were made on vanilla kernels on Debian Lenny with this config:
http://watchdog.sk/lkml/configDo you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Ick, one kernel per day might make this a bit difficult, but if there was any way you could use 'git bisect' to try to narrow this down to the patch that caused this problem, it would be great.
You can mark 2.6.35 as working and 2.6.36 as bad and git will go from there and try to offer you different chances to find the problem.
thanks,
greg k-h
Quoted 11 lines · Greg Kroah-Hartman
Quoted 4 lines
Do you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Ick, one kernel per day might make this a bit difficult, but if there was any way you could use 'git bisect' to try to narrow this down to the patch that caused this problem, it would be great.
You can mark 2.6.35 as working and 2.6.36 as bad and git will go from there and try to offer you different chances to find the problem.
Comparing the output of a perf profile between the good/bad kernels might narrow it down faster than a bisect if something obvious sticks out.
Dave
Bisecting: 5103 revisions left to test after this (roughly 12 steps)
If i'm right, it will takes 12 reboots. I'm really able to reboot only once per day and NOT during weekend so this will take 2,5 weeks.
What about that 'perf' tool ? Can anyone, please, tell me how exactly should i run it to gather usefull data ?
Thank you.
______________________________________________________________
Quoted 12 lines
Od: "Dave Jones"
Komu: Greg KH
Dátum: 17.03.2011 01:53
Predmet: Re: Regression from 2.6.36CC [email protected] On Wed, Mar 16, 2011 at 05:15:19PM -0700, Greg Kroah-Hartman wrote:Quoted 4 lines
Do you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Quoted 6 lines
Ick, one kernel per day might make this a bit difficult, but if there was any way you could use 'git bisect' to try to narrow this down to the patch that caused this problem, it would be great.
You can mark 2.6.35 as working and 2.6.36 as bad and git will go from there and try to offer you different chances to find the problem.
Comparing the output of a perf profile between the good/bad kernels might narrow it down faster than a bisect if something obvious sticks out.
Dave
I have finally completed bisection, here are the results:
a892e2d7dcdfa6c76e60c50a8c7385c65587a2a6 is first bad commit commit a892e2d7dcdfa6c76e60c50a8c7385c65587a2a6
Author: Changli Gao <[email protected]> Date: Tue Aug 10 18:01:35 2010 -0700
vfs: use kmalloc() to allocate fdmem if possible
Use kmalloc() to allocate fdmem if possible.
vmalloc() is used as a fallback solution for fdmem allocation. A new helper function __free_fdtable() is introduced to reduce the lines of code.
A potential bug, vfree() a memory allocated by kmalloc(), is fixed.
:040000 040000 a7b3997bc754f573b4a309cda1a0774ea95c235e 4241a4f2115c60e5c1dc1879c85c9911fa077807 M fs
______________________________________________________________
Quoted 54 lines
Od: "Greg KH" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 17.03.2011 01:15
Predmet: Re: Regression from 2.6.36CC [email protected] On Tue, Mar 15, 2011 at 02:25:27PM +0100, azurIt wrote:Hi,
we are successfully running several very busy web servers on 2.6.32.* and few days ago I decided to upgrade to 2.6.37 (mainly because of blkio cgroup). I installed 2.6.37.2 on one of the servers and very strange things started to happen with Apache web server.
We are using Apache with MPM-ITK ( http://mpm-itk.sesse.net/ ) so it is doing lots of 'fork' and lots of 'setuid'. I have also noticed that problem is happening only on very busy servers.
Everything is ok when Apache is started but as time is passing by, its 'root' processes (Apache processes running under root) are consuming more and more CPU. Finally, the whole server becames very unstable and Apache must be restarted. This is repeating until the load on web sites is much lower (usually on 22:00). Sometimes it takes 3 hours when restart is needed, sometimes only 1 hour (again, depends on load on web sites). Here is the graph of CPU utilization showing the problem (red color), Apache was REstarted at 8:11 and 9:35:
http://watchdog.sk/lkml/cpu-problem.pngHere is how it looks on htop:
http://watchdog.sk/lkml/htop.jpgAnd finally here is how it looks with older kernels (yes, when i install older kernel, problem is gone), notice also that I/O wait is much lower and nicer (blue color):
http://watchdog.sk/lkml/cpu-ok.pngI was also strace-ing Apache processes which were doing problems, here it is:
http://watchdog.sk/lkml/strace.txtI'm not 100% sure but I think that CPU was consumed on 'futex' lines.
I tried several kernel versions and find out that everything BEFORE 2.6.36 is NOT affected and everything AFTER 2.6.36 (included) is affected.
Versions which I tried and were NOT affected by this problem:
2.6.32.*
2.6.35.11Versions which I tried and were affected by this problem:
2.6.36
2.6.36.4
2.6.37.2
2.6.37.3
2.6.38-rc8 (final version was not released yet)
Quoted 7 lines
All tests were made on vanilla kernels on Debian Lenny with this config:
http://watchdog.sk/lkml/configDo you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Ick, one kernel per day might make this a bit difficult, but if there was any way you could use 'git bisect' to try to narrow this down to the patch that caused this problem, it would be great.
You can mark 2.6.35 as working and 2.6.36 as bad and git will go from there and try to offer you different chances to find the problem.
thanks,
greg k-h
Cced few people.
Also the series which introduced this were discussed at:
http://lkml.org/lkml/2010/5/3/53
Quoted 107 lines · azurIt
I have finally completed bisection, here are the results:
a892e2d7dcdfa6c76e60c50a8c7385c65587a2a6is first bad commit commita892e2d7dcdfa6c76e60c50a8c7385c65587a2a6Author: Changli Gao <[email protected]> Date: Tue Aug 10 18:01:35 2010 -0700vfs: use
kmalloc()to allocate fdmem if possibleUse
kmalloc()to allocate fdmem if possible.
vmalloc()is used as a fallback solution for fdmem allocation. A new helper function__free_fdtable()is introduced to reduce the lines of code.A potential bug,
vfree()a memory allocated bykmalloc(), is fixed.[[email protected]: use __GFP_NOWARN, uninline alloc_fdmem() and free_fdmem()]Signed-off-by Changli Gao <[email protected]>Cc Alexander Viro <[email protected]>Cc Jiri Slaby <[email protected]>Cc "Paul E. McKenney" <[email protected]>Cc Alexey Dobriyan <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Avi Kivity <[email protected]>Cc Tetsuo Handa <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>:040000 040000
a7b3997bc754f573b4a309cda1a0774ea95c235e4241a4f2115c60e5c1dc1879c85c9911fa077807M fs______________________________________________________________
Quoted 54 lines
Od: "Greg KH" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 17.03.2011 01:15
Predmet: Re: Regression from 2.6.36CC [email protected] On Tue, Mar 15, 2011 at 02:25:27PM +0100, azurIt wrote:Hi,
we are successfully running several very busy web servers on 2.6.32.* and few days ago I decided to upgrade to 2.6.37 (mainly because of blkio cgroup). I installed 2.6.37.2 on one of the servers and very strange things started to happen with Apache web server.
We are using Apache with MPM-ITK ( http://mpm-itk.sesse.net/ ) so it is doing lots of 'fork' and lots of 'setuid'. I have also noticed that problem is happening only on very busy servers.
Everything is ok when Apache is started but as time is passing by, its 'root' processes (Apache processes running under root) are consuming more and more CPU. Finally, the whole server becames very unstable and Apache must be restarted. This is repeating until the load on web sites is much lower (usually on 22:00). Sometimes it takes 3 hours when restart is needed, sometimes only 1 hour (again, depends on load on web sites). Here is the graph of CPU utilization showing the problem (red color), Apache was REstarted at 8:11 and 9:35:
http://watchdog.sk/lkml/cpu-problem.pngHere is how it looks on htop:
http://watchdog.sk/lkml/htop.jpgAnd finally here is how it looks with older kernels (yes, when i install older kernel, problem is gone), notice also that I/O wait is much lower and nicer (blue color):
http://watchdog.sk/lkml/cpu-ok.pngI was also strace-ing Apache processes which were doing problems, here it is:
http://watchdog.sk/lkml/strace.txtI'm not 100% sure but I think that CPU was consumed on 'futex' lines.
I tried several kernel versions and find out that everything BEFORE 2.6.36 is NOT affected and everything AFTER 2.6.36 (included) is affected.
Versions which I tried and were NOT affected by this problem:
2.6.32.*
2.6.35.11Versions which I tried and were affected by this problem:
2.6.36
2.6.36.4
2.6.37.2
2.6.37.3
2.6.38-rc8 (final version was not released yet)Quoted 7 lines
All tests were made on vanilla kernels on Debian Lenny with this config:
http://watchdog.sk/lkml/configDo you need any other information from me ? I'm able to try other versions or patches but, please, take into account that I have to do this on _production_ server (I failed to reproduce it in testing environment). Also, I'm able to try only one kernel per day.
Ick, one kernel per day might make this a bit difficult, but if there was any way you could use 'git bisect' to try to narrow this down to the patch that caused this problem, it would be great.
Quoted 6 lines
You can mark 2.6.35 as working and 2.6.36 as bad and git will go from there and try to offer you different chances to find the problem.
thanks,
greg k-h
thanks,
Signature · 9 lines
js suse labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Jiri Slaby
Cced few people.
Also the series which introduced this were discussed at:
http://lkml.org/lkml/2010/5/3/53
I guess this is due to that lots of fdt are allocated by kmalloc(), not vmalloc(), and we kfree() them in rcu callback.
How about deferring all of the removal to workqueue? This may hurt performance I think.
Anyway, like the patch below... makes sense?
---
fs/file.c +8 -15
@@ -96,20 +96,14 @@ void free_fdtable_rcu(struct rcu_head *rcu) container_of(fdt, struct files_struct, fdtab));return ; } -if (!is_vmalloc_addr (fdt->fd) && !is_vmalloc_addr (fdt->open_fds)) { -kfree (fdt->fd); -kfree (fdt->open_fds); -kfree (fdt); - }else { - fddef = &get_cpu_var (fdtable_defer_list); -spin_lock (&fddef->lock); - fdt->next = fddef->next; - fddef->next = fdt; -/* vmallocs are handled from the workqueue context */ -schedule_work (&fddef->wq); -spin_unlock (&fddef->lock); -put_cpu_var (fdtable_defer_list); - } + + fddef = &get_cpu_var (fdtable_defer_list); +spin_lock (&fddef->lock); + fdt->next = fddef->next; + fddef->next = fdt; +schedule_work (&fddef->wq); +spin_unlock (&fddef->lock); +put_cpu_var (fdtable_defer_list); } --
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 41 lines · Américo Wang
Quoted 7 lines · Jiri Slaby
Cced few people.
Also the series which introduced this were discussed at:
http://lkml.org/lkml/2010/5/3/53I guess this is due to that lots of fdt are allocated by
kmalloc(), notvmalloc(), and wekfree()them in rcu callback.How about deferring all of the removal to workqueue? This may hurt performance I think.
Anyway, like the patch below... makes sense?
Not-yet-signed-off-by WANG Cong <[email protected]>---
fs/file.c +0
-13@@ -96,20 +96,14 @@ void free_fdtable_rcu(struct rcu_head *rcu) container_of(fdt, struct files_struct, fdtab));return ; } -if (!is_vmalloc_addr (fdt->fd) && !is_vmalloc_addr (fdt->open_fds)) { -kfree (fdt->fd); -kfree (fdt->open_fds); -kfree (fdt); - }else { - fddef = &get_cpu_var (fdtable_defer_list); -spin_lock (&fddef->lock); - fdt->next = fddef->next; - fddef->next = fdt; -/* vmallocs are handled from the workqueue context */ -schedule_work (&fddef->wq); -spin_unlock (&fddef->lock); -put_cpu_var (fdtable_defer_list);
fs/file.c void free_fdtable_rcu(struct rcu_head *rcu) · line 107
Quoted 10 lines
fs/file.c +8
-1- } + + fddef = &get_cpu_var (fdtable_defer_list); +spin_lock (&fddef->lock); + fdt->next = fddef->next; + fddef->next = fdt; +schedule_work (&fddef->wq); +spin_unlock (&fddef->lock); +put_cpu_var (fdtable_defer_list); }
Nope, this makes no sense at all.
Its probably the other way. We want to free those blocks ASAP
A fix would be to make alloc_fdmem() use vmalloc() if size is more than 4 pages, or whatever limit is reached.
We had a similar memory problem in fib_trie in the past : We force a synchronize_rcu() every XXX Mbytes allocated to make sure we dont have too much ram waiting to be freed in rcu queues.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines · Eric Dumazet
We had a similar memory problem in
fib_triein the past : We force asynchronize_rcu()every XXX Mbytes allocated to make sure we dont have too much ram waiting to be freed in rcu queues.
This was done in commit c3059477fce2d956 (ipv4: Use synchronize_rcu() during trie_rebalance())
It was possible in fib_trie because we hold RTNL lock, so managing a counter was free.
In fs case, we might use a percpu_counter if we really want to limit the amount of space.
Now, I am not even sure we should care that much and could just forget about this high order pages use.
fs/file.c +0 -0
@@ -41,12 +41,6 @@ static DEFINE_PER_CPU(struct fdtable_defer,
fdtable_defer_list);
static inline void *alloc_fdmem(unsigned int size) {
- void *data;
-
- data = kmalloc(size, GFP_KERNEL|__GFP_NOWARN);
- if (data != NULL)
- return data;
-
return vmalloc(size);
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet
We had a similar memory problem in
fib_triein the past : We force asynchronize_rcu()every XXX Mbytes allocated to make sure we dont have too much ram waiting to be freed in rcu queues.
I don't think there is too much memory allocated by vmalloc to free. My patch should reduce the size of the memory allocated by vmalloc(). I think the real problem is kfree always returns the memory, whose size is aligned to 2^n pages, and more memory are used than before.
Quoted 4 lines
This was done in commit
c3059477fce2d956(ipv4: Usesynchronize_rcu()duringtrie_rebalance())
Quoted 8 lines
It was possible in
fib_triebecause we hold RTNL lock, so managing a counter was free.In fs case, we might use a
percpu_counterif we really want to limit the amount of space.Now, I am not even sure we should care that much and could just forget about this high order pages use.
In normal cases, only a few fds are used, the ftable isn't larger than one page, so we should use kmalloc to reduce the memory cost. Maybe we should set a upper limit for kmalloc() here. One page?
azurlt, would you please test the patch attached? Thanks.
Signature · 2 lines
Regards, Changli Gao([email protected])
fs/file.c +5 -3
@@ -43,9 +43,11 @@ static inline void *alloc_fdmem(unsigned int size) {void *data; - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; +if (size <=PAGE_SIZE ) { + data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
Quoted 2 lines · Changli Gao
azurlt, would you please test the patch attached? Thanks.
Yes of course, I meant to reverse the patch
(use kmalloc() under PAGE_SIZE, vmalloc() for 'big' allocs)
Dont fallback to vmalloc if kmalloc() fails.
if (size <= PAGE_SIZE)
return kmalloc(size, GFP_KERNEL); else return vmalloc(size);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 10 lines · On Thu, 07 Apr 2011 17:36:26 +0200 Eric Dumazet <[email protected]> wrote:
Le jeudi 07 avril 2011 __ 23:27 +0800, Changli Gao a
__crit:Quoted 2 lines
azurlt, would you please test the patch attached? Thanks.
Yes of course, I meant to reverse the patch
(use
kmalloc()underPAGE_SIZE,vmalloc()for 'big' allocs)
Quoted 8 lines
Dont fallback to vmalloc if
kmalloc()fails.if (size <=
PAGE_SIZE)return kmalloc(size, GFP_KERNEL); else return vmalloc(size);
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Quoted 7 lines
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
Signature · 9 lines
Regards, Changli Gao([email protected]) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 13 lines · On Wed, 13 Apr 2011 09:23:11 +0800 Changli Gao <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
Quoted 7 lines
Quoted 3 lines
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
That theory sounds less likely, but could be tested by using alloc_pages_exact().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · Andrew Morton
Quoted 17 lines · On Wed, 13 Apr 2011 09:23:11 +0800 Changli Gao <[email protected]> wrote:
Quoted 14 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Quoted 7 lines
Quoted 3 lines
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
That theory sounds less likely, but could be tested by using
alloc_pages_exact().
Very unlikely, since fdtable sizes are powers of two, unless you hit sysctl_nr_open and it was changed (default value being 2^20)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Regarding memory fragmentation using malloc....
Dear All,
I am trying to understand how memory fragmentation occurs in linux using many malloc calls.
I am trying to reproduce the page fragmentation problem in linux 2.6.29.x on a linux mobile(without Swap) using a small malloc(in loop) test program of BLOCK_SIZE (64*(4*K)). And then monitoring the page changes in /proc/buddyinfo after each operation.
Quoted 1 line
From the output I can see that the page values under buddyinfo keeps changing. But I am not able to relate these changes with my malloc
BLOCK_SIZE.
I mean with my BLOCK_SIZE of (2^6 x 4K ==> 2^6 PAGES) the 2^6 th block under /proc/buddyinfo should change. But this is not the actual behaviour. Whatever is the blocksize, the buddyinfo changes only for 2^0 or 2^1 or 2^2 or 2^3.
I am trying to measure the level of fragmentation after each page allocation.
Can somebody explain me in detail, how actually /proc/buddyinfo changes after each allocation and deallocation.
Thanks,
Pintu
Re: Regarding memory fragmentation using malloc....
Quoted 9 lines · Pintu Agarwal
Dear All,
I am trying to understand how memory fragmentation occurs in linux using many malloc calls.
I am trying to reproduce the page fragmentation problem in linux 2.6.29.x on a linux mobile(without Swap) using a small malloc(in loop) test program ofBLOCK_SIZE(64*(4*K)). And then monitoring the page changes in/proc/buddyinfoafter each operation.
From the output I can see that the page values under buddyinfo keeps changing. But I am not able to relate these changes with my mallocBLOCK_SIZE. I mean with myBLOCK_SIZEof (2^6 x 4K ==> 2^6 PAGES) the 2^6 th block under/proc/buddyinfoshould change. But this is not the actual behaviour. Whatever is the blocksize, the buddyinfo changes only for 2^0 or 2^1 or 2^2 or 2^3.
Quoted 3 lines
I am trying to measure the level of fragmentation after each page allocation.
Can somebody explain me in detail, how actually/proc/buddyinfochanges after each allocation and deallocation.
What malloc() sees is virtual memory of the process, while buddyinfo shows physical memory pages.
When you malloc() 64K memory, the kernel may not allocate a 64K physical memory at one time
for you.
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: Regarding memory fragmentation using malloc....
Hi,
My requirement is, I wanted to measure memory fragmentation level in linux kernel2.6.29 (ARM cortex A8 without swap). How can I measure fragmentation level(percentage) from /proc/buddyinfo ?
Example : After each page allocation operation, I need to measure fragmentation level. If the level is above 80%, I will trigger a OOM or something to the user. How can I reproduce this memory fragmentation scenario using a sample program?
Here is my sample program: (to check page allocation using malloc)
----------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#define PAGE_SIZE (4*1024)
#define MEM_BLOCK (64*PAGE_SIZE)
#define MAX_LIMIT (16)
int main()
{
char *ptr[MAX_LIMIT+1] = {NULL,};
int i = 0;
printf("Requesting <%d> blocks of memory of block size <%d>........\n",MAX_LIMIT,MEM_BLOCK);
system("cat /proc/buddyinfo");
system("cat /proc/zoneinfo | grep free_pages");
printf("*****************************************\n\n\n");
for(i=0; i<MAX_LIMIT; i++)
{
ptr[i] = (char *)malloc(sizeof(char)*MEM_BLOCK);
if(ptr[i] == NULL)
{
printf("ERROR : malloc failed(counter %d) <%s>\n",i,strerror(errno));
system("cat /proc/buddyinfo");
system("cat /proc/zoneinfo | grep free_pages");
printf("press any key to terminate......");
getchar();
exit(0);
}
memset(ptr[i],1,MEM_BLOCK);
sleep(1);
//system("cat /proc/buddyinfo");
//system("cat /proc/zoneinfo | grep free_pages");
//printf("-----------------------------------------\n");
}
sleep(1);
system("cat /proc/buddyinfo");
system("cat /proc/zoneinfo | grep free_pages");
printf("-----------------------------------------\n");
printf("press any key to end......");
getchar();
for(i=0; i<MAX_LIMIT; i++)
{
if(ptr[i] != NULL)
{
free(ptr[i]);
}
}
printf("DONE !!!\n");
return 0;
}EACH BLOCK SIZE = 64 Pages ==> (64 * 4 * 1024)
TOTAL BLOCKS = 16
----------------------------------------------
In my linux2.6.29 ARM machine, the initial /proc/buddyinfo shows the following:
Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0 Node 1, zone DMA 15 320 423 225 97 26 1 0 0 0 0 0
After running my sample program (with 16 iterations) the buddyinfo output is as follows:
Requesting <16> blocks of memory of block size <262144>........
Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0
Node 1, zone DMA 15 301 419 224 96 27 1 0 0 0 0 0
nr_free_pages 169
nr_free_pages 6545*****************************************
Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0
Node 1, zone DMA 18 2 305 226 96 27 1 0 0 0 0 0
nr_free_pages 169
nr_free_pages 5514-----------------------------------------
The requested block size is 64 pages (2^6) for each block.
But if we see the output after 16 iterations the buddyinfo allocates pages only from Node 1 , (2^0, 2^1, 2^2, 2^3). But the actual allocation should happen from (2^6) block in buddyinfo.
Questions:
1) How to analyse buddyinfo based on each page block size?
2) How and in what scenario the buddyinfo changes?
3) Can we rely completely on buddyinfo information for measuring the level of fragmentation?
Can somebody through some more lights on this???
Thanks,
Pintu
Quoted 38 lines · Américo Wang
From: Américo Wang <[email protected]>
Subject: Re: Regarding memory fragmentation using malloc....
To: "Pintu Agarwal" <[email protected]>
Cc: "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Jiri Slaby" <[email protected]>, "azurIt" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Date: Wednesday, April 13, 2011, 6:44 AMQuoted 3 lines · Pintu Agarwal
Dear All,
I am trying to understand how memory fragmentation
occurs in linux using many malloc calls.
Quoted 1 line
I am trying to reproduce the page fragmentation
problem in linux 2.6.29.x on a linux mobile(without Swap) using a small malloc(in loop) test program of
BLOCK_SIZE(64*(4*K)).Quoted 1 line
And then monitoring the page changes in
/proc/buddyinfoafter each operation.Quoted 1 line
From the output I can see that the page values under
buddyinfo keeps changing. But I am not able to relate these changes with my malloc
BLOCK_SIZE.Quoted 1 line
I mean with my
BLOCK_SIZEof (2^6 x 4K ==> 2^6PAGES) the 2^6 th block under
/proc/buddyinfoshould change. But this is not the actual behaviour.Quoted 1 line
Whatever is the blocksize, the buddyinfo changes only
for 2^0 or 2^1 or 2^2 or 2^3.
Quoted 2 lines
I am trying to measure the level of fragmentation
after each page allocation.
Quoted 1 line
Can somebody explain me in detail, how actually
/proc/buddyinfochanges after each allocation and
deallocation.Quoted 1 line
What
malloc()sees is virtual memory of the process, while buddyinfo
shows physical memory pages.
Quoted 7 lines
When you
malloc()64K memory, the kernel may not allocate a 64K
physical memory at one time
for you.Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: Regarding memory fragmentation using malloc....
Quoted 2 lines · Pintu Agarwal
My requirement is, I wanted to measure memory fragmentation level in linux kernel2.6.29 (ARM cortex A8 without swap). How can I measure fragmentation level(percentage) from
/proc/buddyinfo?
[...]
Quoted 17 lines
In my linux2.6.29 ARM machine, the initial
/proc/buddyinfoshows the following:Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0 Node 1, zone DMA 15 320 423 225 97 26 1 0 0 0 0 0After running my sample program (with 16 iterations) the buddyinfo output is as follows:
Requesting <16> blocks of memory of block size <262144>........Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0 Node 1, zone DMA 15 301 419 224 96 27 1 0 0 0 0 0 nr_free_pages 169 nr_free_pages 6545*****************************************
Node 0, zone DMA 17 22 1 1 0 1 1 0 0 0 0 0 Node 1, zone DMA 18 2 305 226 96 27 1 0 0 0 0 0 nr_free_pages 169 nr_free_pages 5514
Quoted 5 lines
-----------------------------------------
The requested block size is 64 pages (2^6) for each block.
But if we see the output after 16 iterations the buddyinfo allocates pages only from Node 1 , (2^0, 2^1, 2^2, 2^3). But the actual allocation should happen from (2^6) block in buddyinfo.
No. When you call malloc() only virtual address space is allocated. The actual allocation of physical space occurs when user space accesses the memory (either reads or writes) and it happens page at a time.
As a matter of fact, if you have limited number of 0-order pages and allocates in user space block of 64 pages later accessing the memory, what really happens is that kernel allocates the 0-order pages and when it runs out of those, splits a 1-order page into two 0-order pages and takes one of those.
Because of MMU, fragmentation of physical memory is not an issue for normal user space programs.
It becomes an issue once you deal with hardware that does not have MMU nor support for scatter-getter DMA or with some big kernel structures.
/proc/buddyinfo tells you how many free pages of given order there are in the system. You may interpret it in such a way that the bigger number of the low order pages the bigger fragmentation of physical memory. If there was no fragmentation (for some definition of the term) you'd get only the highest order pages and at most one page for each lower order.
Again though, this fragmentation is not an issue for user space programs.
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
Re: Regarding memory fragmentation using malloc....
Thanks Mr. Michal for all your comments :)
As I can understand from your comments that, malloc from user space will not have much impact on memory fragmentation. Will the memory fragmentation be visible if I do kmalloc from the kernel module????
Quoted 6 lines
No. When you call
malloc()only virtual address space is allocated. The
actual allocation of physical space occurs when user space accesses the
memory (either reads or writes) and it happens page at a time.
Here, if I do memset then I am accessing the memory...right? That I am doing already in my sample program.
Quoted 5 lines
what really happens is that kernel allocates the 0-order pages and when
it runs out of those, splits a 1-order page into two 0-order pages and
takes one of those.
Actually, if I understand buddy allocator, it allocates pages from top to bottom. That means it checks for the highest order block that can be allocated, if possible it allocates pages from that block otherwise split the next highest block into two. What will happen if the next higher blocks are all empty???
Is the memory fragmentation is always a cause of the kernel space program and not user space at all??
Can you provide me with some references for migitating memory fragmentation in linux?
Thanks,
Pintu
Quoted 116 lines · Michal Nazarewicz
From: Michal Nazarewicz <[email protected]>
Subject: Re: Regarding memory fragmentation using malloc....
To: "Américo Wang" <[email protected]>, "Pintu Agarwal" <[email protected]>
Cc: "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Jiri Slaby" <[email protected]>, "azurIt" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Date: Wednesday, April 13, 2011, 10:25 AMQuoted 1 line · Pintu Agarwal
My requirement is, I wanted to measure memory
fragmentation level in linux kernel2.6.29 (ARM cortex A8 without swap).
Quoted 1 line
How can I measure fragmentation level(percentage) from
/proc/buddyinfo?[...]
Quoted 1 line
In my linux2.6.29 ARM machine, the initial
/proc/buddyinfoshows the following:Quoted 1 line
Node 0, zone DMA
17 22
1 1 0
1 1
0 0 0
0 0Quoted 1 line
Node 1, zone DMA
15 320 423
225 97
26 1
0 0 0
0 0Quoted 2 lines
After running my sample program (with 16 iterations)
the buddyinfo output is as follows:
Quoted 1 line
Requesting <16> blocks of memory of block size
<262144>........
Quoted 1 line
Node 0, zone DMA
17 22
1 1 0
1 1
0 0 0
0 0Quoted 1 line
Node 1, zone DMA
15 301 419
224 96
27 1
0 0 0
0 0Quoted 6 lines
nr_free_pages 169
nr_free_pages 6545
*****************************************Node 0, zone DMA
17 22
1 1 0
1 1
0 0 0
0 0Quoted 1 line
Node 1, zone DMA
18 2
305 226 96
27 1
0 0 0
0 0Quoted 5 lines
nr_free_pages 169
nr_free_pages 5514
-----------------------------------------The requested block size is 64 pages (2^6) for each
block.
Quoted 1 line
But if we see the output after 16 iterations the
buddyinfo allocates pages only from Node 1 , (2^0, 2^1, 2^2, 2^3).
Quoted 1 line
But the actual allocation should happen from (2^6)
block in buddyinfo.
No. When you call
malloc()only virtual address space is allocated. The
actual allocation of physical space occurs when user space accesses the
memory (either reads or writes) and it happens page at a time.As a matter of fact, if you have limited number of 0-order pages and
allocates in user space block of 64 pages later accessing the memory,
what really happens is that kernel allocates the 0-order pages and when
it runs out of those, splits a 1-order page into two 0-order pages and
takes one of those.Because of MMU, fragmentation of physical memory is not an issue for
normal user space programs.It becomes an issue once you deal with hardware that does not have MMU
nor support for scatter-getter DMA or with some big kernel structures.
/proc/buddyinfotells you how many free pages of given order there are
in the system. You may interpret it in such a way that the bigger number
of the low order pages the bigger fragmentation of physical memory. If
there was no fragmentation (for some definition of the term) you'd get only
the highest order pages and at most one page for each lower order.Again though, this fragmentation is not an issue for user space programs.
Quoted 10 lines
--Best regards,
_
_
.o. | Liege of Serenely Enlightened Majesty of
o' \,=./ `o
..o | Computer Science, Michal "mina86"
Nazarewicz (o o)
ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: Regarding memory fragmentation using malloc....
Quoted 1 line · Pintu Agarwal
As I can understand from your comments that, malloc from user space will not have much impact on memory fragmentation.
It has an impact, just like any kind of allocation, it just don't care about fragmentation of physical memory. You can have only 0-order pages and successfully allocate megabytes of memory with malloc().
Quoted 2 lines
Will the memory fragmentation be visible if I do kmalloc from the kernel module????
It will be more visible in the sense that if you allocate 8 KiB, kernel will have to find 8 KiB contiguous physical memory (ie. 1-order page).
Quoted 5 lines
Quoted 3 lines
No. When you call
malloc()only virtual address space is allocated. The actual allocation of physical space occurs when user space accesses the memory (either reads or writes) and it happens page at a time.Here, if I do memset then I am accessing the memory...right? That I am doing already in my sample program.
Yes. But note that even though it's a single memset() call, you are accessing page at a time and kernel is allocating page at a time.
On some architectures (not ARM) you could access two pages with a single instructions but I think that would result in two page faults anyway. I might be wrong though, the details are not important though.
Quoted 7 lines
Quoted 5 lines
what really happens is that kernel allocates the 0-order pages and when
it runs out of those, splits a 1-order page into two 0-order pages and
takes one of those.Actually, if I understand buddy allocator, it allocates pages from top to bottom.
No. If you want to allocate a single 0-order page, buddy looks for a a free 0-order page. If one is not found, it will look for 1-order page and split it. This goes up till buddy reaches (MAX_ORDER-1)-page.
Quoted 1 line
Is the memory fragmentation is always a cause of the kernel space program and not user space at all?
Well, no. If you allocate memory in user space, kernel will have to allocate physical memory and *every* allocation may contribute to fragmentation. The point is, that all allocations from user-space are single-page allocations even if you malloc() MiBs of memory.
Quoted 1 line
Can you provide me with some references for migitating memory fragmentation in linux?
I'm not sure what you mean by that.
Signature · 11 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: Regarding memory fragmentation using malloc....
Hello Mr. Michal,
Thanks for your comments.
Sorry. There was a small typo in my last sentence (mitigating not *migitating* memory fragmentation) That means how can I measure the memory fragmentation either from user space or from kernel space. Is there a way to measure the amount of memory fragmentation in linux?
Can you provide me some references for that?
Thanks,
Pintu
Quoted 95 lines · Michal Nazarewicz
From: Michal Nazarewicz <[email protected]>
Subject: Re: Regarding memory fragmentation using malloc....
To: "Américo Wang" <[email protected]>, "Pintu Agarwal" <[email protected]>
Cc: "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Jiri Slaby" <[email protected]>, "azurIt" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Date: Thursday, April 14, 2011, 5:47 AMQuoted 1 line · Pintu Agarwal
As I can understand from your comments that, malloc
from user space will not have much impact on memory fragmentation.
It has an impact, just like any kind of allocation, it just don't care about
fragmentation of physical memory. You can have only 0-order pages and
successfully allocate megabytes of memory withmalloc().Quoted 1 line
Will the memory fragmentation be visible if I do
kmalloc from
Quoted 1 line
the kernel module????
It will be more visible in the sense that if you allocate 8 KiB, kernel will
have to find 8 KiB contiguous physical memory (ie. 1-order page).Quoted 1 line
Quoted 1 line
No. When you call
malloc()only virtualaddress space is allocated.
Quoted 1 line
Quoted 1 line
The actual allocation of physical space occurs
when user space accesses
Quoted 1 line
Quoted 1 line
the memory (either reads or writes) and it happens
page at a time.
Quoted 2 lines
Here, if I do memset then I am accessing the
memory...right? That I am doing already in my sample program.
Yes. But note that even though it's a single
memset()call, you are
accessing page at a time and kernel is allocating page at a time.On some architectures (not ARM) you could access two pages with a single
instructions but I think that would result in two page faults anyway. I
might be wrong though, the details are not important though.Quoted 1 line
Quoted 1 line
what really happens is that kernel allocates the
0-order
Quoted 2 lines
Quoted 2 lines
pages and when
it runs out of those, splits a 1-order page intotwo
Quoted 4 lines
Quoted 2 lines
0-order pages and
takes one of those.Actually, if I understand buddy allocator, it
allocates pages from top to bottom.
No. If you want to allocate a single 0-order page, buddy looks for a
a free 0-order page. If one is not found, it will look for 1-order page
and split it. This goes up till buddy reaches (MAX_ORDER-1)-page.Quoted 1 line
Is the memory fragmentation is always a cause of the
kernel space program and not user space at all?
Well, no. If you allocate memory in user space, kernel will have to
allocate physical memory and *every* allocation may contribute to
fragmentation. The point is, that all allocations from user-space are
single-page allocations even if youmalloc()MiBs of memory.Quoted 1 line
Can you provide me with some references for migitating
memory fragmentation in linux?
I'm not sure what you mean by that.
--Best regards,
_
_
.o. | Liege of Serenely Enlightened Majesty of
o' \,=./ `o
..o | Computer Science, Michal "mina86"
Nazarewicz (o o)
ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
Quoted 11 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm'
in
the body to [email protected].
For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]">
[email protected]
</a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: Regarding memory fragmentation using malloc....
Quoted 3 lines · Pintu Agarwal
Sorry. There was a small typo in my last sentence (mitigating not *migitating* memory fragmentation) That means how can I measure the memory fragmentation either from user space or from kernel space. Is there a way to measure the amount of memory fragmentation in linux?
I'm still not entirely sure what you need. You may try to measure fragmentation by the number of low order pages -- the more low order pages compared to high order pages the bigger the fragmentation.
As of how to mitigate... There's memory compaction. There's some optimisations in buddy system. I'm probably not the best person to ask anyway.
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
Andrew Morton
maintainerQuoted 24 lines · On Wed, 13 Apr 2011 04:37:36 +0200 Eric Dumazet <[email protected]> wrote:
Le mardi 12 avril 2011 __ 18:31 -0700, Andrew Morton a
__crit:Quoted 23 lines · On Wed, 13 Apr 2011 09:23:11 +0800 Changli Gao <[email protected]> wrote:
Quoted 21 lines
Quoted 7 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Quoted 7 lines
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
Quoted 7 lines
Quoted 3 lines
That theory sounds less likely, but could be tested by using
alloc_pages_exact().Very unlikely, since fdtable sizes are powers of two, unless you hit
sysctl_nr_openand it was changed (default value being 2^20)
So am I correct in believing that this regression is due to the high-order allocations putting excess stress onto page reclaim?
If so, then how large _are_ these allocations? This perhaps can be determined from /proc/slabinfo. They must be pretty huge, because slub likes to do excessively-large allocations and the system handles that reasonably well.
I suppose that a suitable fix would be
From: Andrew Morton <[email protected]>
Azurit reports large increases in system time after 2.6.36 when running Apache. It was bisected down to a892e2d7dcdfa6c76e6 ("vfs: use kmalloc() to allocate fdmem if possible").
That patch caused the vfs to use kmalloc() for very large allocations and this is causing excessive work (and presumably excessive reclaim) within the page allocator.
Fix it by falling back to vmalloc() earlier - when the allocation attempt would have been considered "costly" by reclaim.
---
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
fs/file.c renamed from fs/file.c~a +10 -7
@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 2 lines · On Wed, 13 Apr 2011 14:16:00 -0700 Andrew Morton <[email protected]>…
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
bah, stupid compiler.
fs/file.c renamed from fs/file.c~vfs-avoid-large-kmallocs-for-the-fdtable +11 -7
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/mmzone.h> #include <linux/time.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -39,14 +40,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ +if (size <= (PAGE_SIZE <<PAGE_ALLOC_COSTLY_ORDER )) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew,
which kernel versions will include this patch ? Thank you.
azur
______________________________________________________________
Quoted 51 lines
Od: "Andrew Morton" <[email protected]>
Komu: Eric Dumazet <[email protected]>,Changli Gao <[email protected]>,AmA(C)rico Wang <[email protected]>,Jiri Slaby <[email protected]>, azurIt <[email protected]>,[email protected], [email protected],[email protected], Jiri Slaby <[email protected]>,Mel Gorman <[email protected]> DA!tum: 13.04.2011 23:26
Predmet: Re: Regression from 2.6.36Quoted 2 lines · On Wed, 13 Apr 2011 14:16:00 -0700 Andrew Morton <[email protected]>…
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)bah, stupid compiler.
fs/file.c renamed from fs/file.c~vfs-avoid-large-kmallocs-for-the-fdtable +11
-7@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/mmzone.h> #include <linux/time.h> #include <linux/sched.h> #include <linux/slab.h> @@ -39,14 +40,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ +if (size <= (PAGE_SIZE <<PAGE_ALLOC_COSTLY_ORDER )) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }_
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 1 line · On Tue, 19 Apr 2011 21:29:20 +0200 "azurIt" <[email protected]> wrote:
which kernel versions will include this patch ? Thank you.
Probably 2.6.39. If so, some later 2.6.38.x too.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 2 lines · On Wed, 13 Apr 2011 14:16:00 -0700 Andrew Morton <[email protected]>…
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
bah, stupid compiler.
fs/file.c renamed from fs/file.c~vfs-avoid-large-kmallocs-for-the-fdtable +11 -7
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/mmzone.h> #include <linux/time.h> #include <linux/sched.h> #include <linux/slab.h>
@@ -39,14 +40,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ +if (size <= (PAGE_SIZE <<PAGE_ALLOC_COSTLY_ORDER )) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
_
Quoted 41 lines · Andrew Morton
Azurit reports large increases in system time after 2.6.36 when running Apache. It was bisected down to
a892e2d7dcdfa6c76e6("vfs: usekmalloc()to allocate fdmem if possible").That patch caused the vfs to use
kmalloc()for very large allocations and this is causing excessive work (and presumably excessive reclaim) within the page allocator.Fix it by falling back to
vmalloc()earlier - when the allocation attempt would have been considered "costly" by reclaim.Reported-by azurIt <[email protected]>Cc Changli Gao <[email protected]>Cc Americo Wang <[email protected]>Cc Jiri Slaby <[email protected]>Cc Eric Dumazet <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)diff -puN
fs/file.c~afs/file.cfs/file.c renamed from fs/file.c~a +3
-7@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to
fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 55
Quoted 10 lines
fs/file.c renamed from fs/file.c~a +7
-0+* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
It's a shame that we can't at least try kmalloc() with sufficiently large sizes by doing something like
gfp_t flags = GFP_NOWAIT | __GFP_NOWARN; if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) flags |= GFP_KERNEL; data = kmalloc(size, flags); if (data) return data; return vmalloc(size);
which would at least attempt to use the slab allocator.
Andrew Morton
maintainerQuoted 34 lines · On Wed, 13 Apr 2011 14:44:16 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 11 lines
fs/file.c renamed from fs/file.c~a +2
-7-static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 54
Quoted 10 lines
fs/file.c renamed from fs/file.c~a +8
-0+* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }It's a shame that we can't at least try
kmalloc()with sufficiently large sizes by doing something likegfp_t flags = GFP_NOWAIT | __GFP_NOWARN; if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) flags |= GFP_KERNEL; data = kmalloc(size, flags); if (data) return data; return vmalloc(size);
Quoted 1 line
which would at least attempt to use the slab allocator.
Maybe. If the fdtable is that huge then the fork() is probably going to be pretty slow anyway. And the large allocation might cause depletion of high-order free pages and might cause fragmentation of even-higher-order pages by splitting them up. </handwaving>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Eric Dumazet
Acked-byQuoted 3 lines · Andrew Morton
So am I correct in believing that this regression is due to the high-order allocations putting excess stress onto page reclaim?
I suppose so.
Quoted 61 lines
If so, then how large _are_ these allocations? This perhaps can be determined from
/proc/slabinfo. They must be pretty huge, because slub likes to do excessively-large allocations and the system handles that reasonably well.I suppose that a suitable fix would be
From: Andrew Morton <[email protected]>
Azurit reports large increases in system time after 2.6.36 when running Apache. It was bisected down to
a892e2d7dcdfa6c76e6("vfs: usekmalloc()to allocate fdmem if possible").That patch caused the vfs to use
kmalloc()for very large allocations and this is causing excessive work (and presumably excessive reclaim) within the page allocator.Fix it by falling back to
vmalloc()earlier - when the allocation attempt would have been considered "costly" by reclaim.Reported-by azurIt <[email protected]>Cc Changli Gao <[email protected]>Cc Americo Wang <[email protected]>Cc Jiri Slaby <[email protected]>Cc Eric Dumazet <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)diff -puN
fs/file.c~afs/file.cfs/file.c renamed from fs/file.c~a +10
-7@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
Quoted 2 lines
_
#define PAGE_ALLOC_COSTLY_ORDER 3
On x86_64, this means we try kmalloc() up to 4096 files in fdtable.
Thanks !
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrew Morton
maintainerQuoted 27 lines · On Thu, 14 Apr 2011 04:10:58 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 27 lines
fs/file.c renamed from fs/file.c~a +10
-7@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
Quoted 8 lines
Quoted 2 lines
_
Acked-by Eric Dumazet <[email protected]>#define
PAGE_ALLOC_COSTLY_ORDER3On
x86_64, this means we trykmalloc()up to 4096 files in fdtable.
Thanks. I added the cc:stable to the changelog.
It'd be nice to get this tested if poss, to confrm that it actually fixes things.
Also, Melpoke.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 36 lines · Andrew Morton
Quoted 34 lines · On Thu, 14 Apr 2011 04:10:58 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 27 lines
fs/file.c renamed from fs/file.c~a +10
-7@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }Quoted 2 lines
_
Acked-by Eric Dumazet <[email protected]>#define
PAGE_ALLOC_COSTLY_ORDER3
Quoted 8 lines
Quoted 1 line
On
x86_64, this means we trykmalloc()up to 4096 files in fdtable.Thanks. I added the cc:stable to the changelog.
It'd be nice to get this tested if poss, to confrm that it actually fixes things.
Also, Melpoke.
Azurit, could you check how many fds are opened by your apache servers ? (must be related to number of virtual hosts / acces_log / error_log files)
Pick one pid from ps list
ps aux | grep apache
ls /proc/{pid_of_one_apache}/fd | wc -l
or
lsof -p { pid_of_one_apache} | tail -n 2
apache2 8501 httpadm 13w REG 104,7 2350407 3866638 /data/logs/httpd/rewrites.log
apache2 8501 httpadm 14r 0000 0,10 0 263148343 eventpoll
Here it's "14"
Thanks
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Here it is:
# ls /proc/31416/fd | wc -l 5926
azur
______________________________________________________________
Quoted 73 lines
Od: "Eric Dumazet" <[email protected]>
Komu: Andrew Morton <[email protected]>
Dátum: 14.04.2011 08:32
Predmet: Re: Regression from 2.6.36CC: "Changli Gao" <[email protected]>, "Américo Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>, "Mel Gorman" <[email protected]>
Quoted 36 lines · Andrew Morton
Quoted 34 lines · On Thu, 14 Apr 2011 04:10:58 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 27 lines
fs/file.c renamed from fs/file.c~a +10
-7@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data; - - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) { +void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }Quoted 2 lines
_
Acked-by Eric Dumazet <[email protected]>#define
PAGE_ALLOC_COSTLY_ORDER3Quoted 8 lines
Quoted 1 line
On
x86_64, this means we trykmalloc()up to 4096 files in fdtable.Thanks. I added the cc:stable to the changelog.
It'd be nice to get this tested if poss, to confrm that it actually fixes things.
Also, Melpoke.
Azurit, could you check how many fds are opened by your apache servers ? (must be related to number of virtual hosts /
acces_log/error_logfiles)Pick one pid from ps list
ps aux | grep apachels
/proc/{pid_of_one_apache}/fd| wc -lor
lsof -p {
pid_of_one_apache} | tail -n 2
apache2 8501 httpadm 13w REG 104,7 2350407 3866638 /data/logs/httpd/rewrites.log
apache2 8501 httpadm 14r 0000 0,10 0 263148343 eventpollHere it's "14"
Thanks
Quoted 5 lines · azurIt
Here it is:
# ls /proc/31416/fd | wc -l 5926
Hmm, if its a 32bit kernel, I am afraid Andrew patch wont solve the problem...
[On 32bit kernel, we still use kmalloc() up to 8192 files ]
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
It's completely 64bit system.
______________________________________________________________
Quoted 16 lines
Od: "Eric Dumazet" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 14.04.2011 12:28
Predmet: Re: Regression from 2.6.36CC: "Andrew Morton" <[email protected]>, "Changli Gao" <[email protected]>, "Américo Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>, "Mel Gorman" <[email protected]>
Quoted 5 lines · azurIt
Here it is:
# ls /proc/31416/fd | wc -l 5926Hmm, if its a 32bit kernel, I am afraid Andrew patch wont solve the problem...
Quoted 9 lines
[On 32bit kernel, we still use
kmalloc()up to 8192 files ]--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 31 lines · Andrew Morton
Quoted 28 lines · On Wed, 13 Apr 2011 04:37:36 +0200 Eric Dumazet <[email protected]> wrote:
Le mardi 12 avril 2011 __ 18:31 -0700, Andrew Morton a
__crit:Quoted 26 lines · On Wed, 13 Apr 2011 09:23:11 +0800 Changli Gao <[email protected]> wrote:
Quoted 14 lines
Quoted 11 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
Quoted 7 lines
Quoted 3 lines
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
That theory sounds less likely, but could be tested by using
alloc_pages_exact().
Quoted 7 lines
Quoted 3 lines
Very unlikely, since fdtable sizes are powers of two, unless you hit
sysctl_nr_openand it was changed (default value being 2^20)So am I correct in believing that this regression is due to the high-order allocations putting excess stress onto page reclaim?
This is very plausible but it would be nice to get confirmation on what the size of the fdtable was to be sure. If it's big enough for high-order allocations and it's a fork-heavy workload with memory mostly in use, the fork() latencies could be getting very high. In addition, each fork is potentially kicking kswapd awake (to rebalance the zone for higher orders). I do not see CONFIG_COMPACTION enabled meaning that if I'm right in that kswapd is awake and fork() is entering direct reclaim, then we are lumpy reclaiming as well which can stall pretty severely.
Quoted 5 lines
If so, then how large _are_ these allocations? This perhaps can be determined from
/proc/slabinfo. They must be pretty huge, because slub likes to do excessively-large allocations and the system handles that reasonably well.
I'd be interested in finding out the value of /proc/sys/fs/file-max and the output of ulimit -n (max open files) for the main server is. This should help us determine what the size of the fdtable is.
Quoted 39 lines
I suppose that a suitable fix would be
From: Andrew Morton <[email protected]>
Azurit reports large increases in system time after 2.6.36 when running Apache. It was bisected down to
a892e2d7dcdfa6c76e6("vfs: usekmalloc()to allocate fdmem if possible").That patch caused the vfs to use
kmalloc()for very large allocations and this is causing excessive work (and presumably excessive reclaim) within the page allocator.Fix it by falling back to
vmalloc()earlier - when the allocation attempt would have been considered "costly" by reclaim.Reported-by azurIt <[email protected]>Cc Changli Gao <[email protected]>Cc Americo Wang <[email protected]>Cc Jiri Slaby <[email protected]>Cc Eric Dumazet <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)diff -puN
fs/file.c~afs/file.cfs/file.c renamed from fs/file.c~a +1
-2@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data;
fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 48
Quoted 10 lines
fs/file.c renamed from fs/file.c~a +5
-5- - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) {
The reporter will need to retest this is really ok. The patch that was reported to help avoided high-order allocations entirely. If fork-heavy workloads are really entering direct reclaim and increasing fork latency enough to ruin performance, then this patch will also suffer. How much it helps depends on how big fdtable.
fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 55
Quoted 7 lines
fs/file.c renamed from fs/file.c~a +4
-0+void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }
I'm attaching a primitive perl script that reports high-order allocation latencies. I'd be interesting to see what the output of it looks like, particularly when the server is in trouble if the bug reporter as the time.
Signature · 2 lines
Mel Gorman SUSE Labs
Also this new patch is working fine and fixing the problem.
Mel, I cannot run your script:
# perl watch-highorder-latency.pl Failed to open /sys/kernel/debug/tracing/set_ftrace_filter for writing at watch-highorder-latency.pl line 17.
# ls -ld /sys/kernel/debug/ ls: cannot access /sys/kernel/debug/: No such file or directory
azur
______________________________________________________________
Quoted 122 lines
Od: "Mel Gorman" <[email protected]>
Komu: Andrew Morton <[email protected]>
Dátum: 14.04.2011 12:25
Predmet: Re: Regression from 2.6.36CC: "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Am?rico Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Quoted 31 lines · Andrew Morton
Quoted 28 lines · On Wed, 13 Apr 2011 04:37:36 +0200 Eric Dumazet <[email protected]> wrote:
Le mardi 12 avril 2011 __ 18:31 -0700, Andrew Morton a
__crit:Quoted 26 lines · On Wed, 13 Apr 2011 09:23:11 +0800 Changli Gao <[email protected]> wrote:
Quoted 14 lines
Quoted 11 lines · Andrew Morton
It's somewhat unclear (to me) what caused this regression.
Is it because the kernel is now doing large kmalloc()s for the fdtable, and this makes the page allocator go nuts trying to satisfy high-order page allocation requests?
Is it because the kernel now will usually free the fdtable synchronously within the rcu callback, rather than deferring this to a workqueue?
Quoted 7 lines
Quoted 3 lines
The latter seems unlikely, so I'm thinking this was a case of high-order-allocations-considered-harmful?
Maybe, but I am not sure. Maybe my patch causes too many inner fragments. For example, when asking for 5 pages, get 8 pages, and 3 pages are wasted, then memory thrash happens finally.
That theory sounds less likely, but could be tested by using
alloc_pages_exact().Quoted 7 lines
Quoted 3 lines
Very unlikely, since fdtable sizes are powers of two, unless you hit
sysctl_nr_openand it was changed (default value being 2^20)So am I correct in believing that this regression is due to the high-order allocations putting excess stress onto page reclaim?
This is very plausible but it would be nice to get confirmation on what the size of the fdtable was to be sure. If it's big enough for high-order allocations and it's a fork-heavy workload with memory mostly in use, the
fork()latencies could be getting very high. In addition, each fork is potentially kicking kswapd awake (to rebalance the zone for higher orders). I do not seeCONFIG_COMPACTIONenabled meaning that if I'm right in that kswapd is awake andfork()is entering direct reclaim, then we are lumpy reclaiming as well which can stall pretty severely.Quoted 5 lines
If so, then how large _are_ these allocations? This perhaps can be determined from
/proc/slabinfo. They must be pretty huge, because slub likes to do excessively-large allocations and the system handles that reasonably well.I'd be interested in finding out the value of
/proc/sys/fs/file-maxand the output of ulimit -n (max open files) for the main server is. This should help us determine what the size of the fdtable is.Quoted 39 lines
I suppose that a suitable fix would be
From: Andrew Morton <[email protected]>
Azurit reports large increases in system time after 2.6.36 when running Apache. It was bisected down to
a892e2d7dcdfa6c76e6("vfs: usekmalloc()to allocate fdmem if possible").That patch caused the vfs to use
kmalloc()for very large allocations and this is causing excessive work (and presumably excessive reclaim) within the page allocator.Fix it by falling back to
vmalloc()earlier - when the allocation attempt would have been considered "costly" by reclaim.Reported-by azurIt <[email protected]>Cc Changli Gao <[email protected]>Cc Americo Wang <[email protected]>Cc Jiri Slaby <[email protected]>Cc Eric Dumazet <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)diff -puN
fs/file.c~afs/file.cfs/file.c renamed from fs/file.c~a +1
-2@@ -39,14 +39,17 @@ int sysctl_nr_open_max = 1024 * 1024; /**/ static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); -static inline void *alloc_fdmem (unsigned int size) +static void *alloc_fdmem (unsigned int size) { -void *data;fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 48
Quoted 10 lines
fs/file.c renamed from fs/file.c~a +5
-5- - data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); -if (data !=NULL ) -return data; - +/* +* Very large allocations can stress page reclaim, so fall back to +* vmalloc() if the allocation size will be considered "large" by the VM. +*/ + if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) {The reporter will need to retest this is really ok. The patch that was reported to help avoided high-order allocations entirely. If fork-heavy workloads are really entering direct reclaim and increasing fork latency enough to ruin performance, then this patch will also suffer. How much it helps depends on how big fdtable.
Quoted 18 lines
fs/file.c int sysctl_nr_open_max = 1024 * 1024; /* · line 55
Quoted 7 lines
fs/file.c renamed from fs/file.c~a +4
-0+void *data =kmalloc (size,GFP_KERNEL |__GFP_NOWARN); +if (data !=NULL ) +return data; + }return vmalloc (size); }I'm attaching a primitive perl script that reports high-order allocation latencies. I'd be interesting to see what the output of it looks like, particularly when the server is in trouble if the bug reporter as the time.
Signature · 2 lines
Mel Gorman SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · azurIt
Also this new patch is working fine and fixing the problem.
Mel, I cannot run your script:
# perl watch-highorder-latency.pl Failed to open /sys/kernel/debug/tracing/set_ftrace_filter for writing at watch-highorder-latency.pl line 17.# ls -ld /sys/kernel/debug/ ls: cannot access /sys/kernel/debug/: No such file or directory
mount -t debugfs none /sys/kernel/debug
If it still doesn't work, sysfs or the necessary FTRACE options are not enabled on your .config. I'll give you a list if that is the case.
Thanks.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
# mount -t debugfs none /sys/kernel/debug mount: mount point /sys/kernel/debug does not exist
# mkdir /sys/kernel/debug mkdir: cannot create directory `/sys/kernel/debug': No such file or directory
config file used for testing is here:
http://watchdog.sk/lkml/config
azur
______________________________________________________________
Quoted 18 lines
Od: "Mel Gorman" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 15.04.2011 12:47
Predmet: Re: Regression from 2.6.36CC: "Mel Gorman" <[email protected]>, "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Am?rico Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Quoted 10 lines · azurIt
Also this new patch is working fine and fixing the problem.
Mel, I cannot run your script:
# perl watch-highorder-latency.pl Failed to open /sys/kernel/debug/tracing/set_ftrace_filter for writing at watch-highorder-latency.pl line 17.# ls -ld /sys/kernel/debug/ ls: cannot access /sys/kernel/debug/: No such file or directory
Quoted 16 lines
mount -t debugfs none
/sys/kernel/debugIf it still doesn't work, sysfs or the necessary FTRACE options are not enabled on your .config. I'll give you a list if that is the case.
Thanks.
Signature · 7 lines
Mel Gorman SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · azurIt
# mount -t debugfs none /sys/kernel/debug mount: mount point /sys/kernel/debug does not exist# mkdir /sys/kernel/debug mkdir: cannot create directory `/sys/kernel/debug': No such file or directory
Mount sysfs first
mount -t sysfs none /sys
Quoted 4 lines
config file used for testing is here:
http://watchdog.sk/lkml/config
Try setting the following
CONFIG_TRACEPOINTS=yCONFIG_STACKTRACE=yCONFIG_USER_STACKTRACE_SUPPORT=yCONFIG_NOP_TRACER=yCONFIG_TRACER_MAX_TRACE=yCONFIG_FTRACE_NMI_ENTER=yCONFIG_CONTEXT_SWITCH_TRACER=yCONFIG_GENERIC_TRACER=yCONFIG_FTRACE=yCONFIG_FUNCTION_TRACER=yCONFIG_FUNCTION_GRAPH_TRACER=yCONFIG_IRQSOFF_TRACER=yCONFIG_SCHED_TRACER=yCONFIG_FTRACE_SYSCALLS=yCONFIG_STACK_TRACER=yCONFIG_BLK_DEV_IO_TRACE=yCONFIG_DYNAMIC_FTRACE=yCONFIG_FTRACE_MCOUNT_RECORD=yCONFIG_FTRACE_SELFTEST=yCONFIG_FTRACE_STARTUP_TEST=yCONFIG_MMIOTRACE=yCONFIG_HAVE_MMIOTRACE_SUPPORT=y
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
sysfs was already mounted:
# mount sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
I have enabled all of the options you suggested and also CONFIG_DEBUG_FS ;) I will boot new kernel this night. Hope it won't degraded performance much..
______________________________________________________________
Quoted 39 lines
Od: "Mel Gorman" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 15.04.2011 13:17
Predmet: Re: Regression from 2.6.36CC: "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Am?rico Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Quoted 6 lines · azurIt
# mount -t debugfs none /sys/kernel/debug mount: mount point /sys/kernel/debug does not exist# mkdir /sys/kernel/debug mkdir: cannot create directory `/sys/kernel/debug': No such file or directoryMount sysfs first
mount -t sysfs none /sys
Quoted 4 lines
config file used for testing is here:
http://watchdog.sk/lkml/configTry setting the following
CONFIG_TRACEPOINTS=yCONFIG_STACKTRACE=yCONFIG_USER_STACKTRACE_SUPPORT=yCONFIG_NOP_TRACER=yCONFIG_TRACER_MAX_TRACE=yCONFIG_FTRACE_NMI_ENTER=yCONFIG_CONTEXT_SWITCH_TRACER=yCONFIG_GENERIC_TRACER=yCONFIG_FTRACE=yCONFIG_FUNCTION_TRACER=yCONFIG_FUNCTION_GRAPH_TRACER=yCONFIG_IRQSOFF_TRACER=yCONFIG_SCHED_TRACER=yCONFIG_FTRACE_SYSCALLS=y
Quoted 19 lines
CONFIG_STACK_TRACER=yCONFIG_BLK_DEV_IO_TRACE=yCONFIG_DYNAMIC_FTRACE=yCONFIG_FTRACE_MCOUNT_RECORD=yCONFIG_FTRACE_SELFTEST=yCONFIG_FTRACE_STARTUP_TEST=yCONFIG_MMIOTRACE=yCONFIG_HAVE_MMIOTRACE_SUPPORT=ySignature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · azurIt
sysfs was already mounted:
# mount sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)I have enabled all of the options you suggested and also
CONFIG_DEBUG_FS;) I will boot new kernel this night. Hope it won't degraded performance much..
It's only for curiousity's sake. As you report the patch fixes the problem, it matches the theory that it's allocator latency. The script would confirm it for sure, but it's not a high priority.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
So it's really not necessary ? It would be better for us if you can go without it cos it means to run buggy kernel for one more day.
Which kernel versions will include this fix ?
Thank you very much!
azur
______________________________________________________________
Quoted 13 lines
Od: "Mel Gorman" <[email protected]>
Komu: azurIt <[email protected]>
Dátum: 15.04.2011 15:01
Predmet: Re: Regression from 2.6.36CC: "Andrew Morton" <[email protected]>, "Eric Dumazet" <[email protected]>, "Changli Gao" <[email protected]>, "Am?rico Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], [email protected], [email protected], "Jiri Slaby" <[email protected]>
Quoted 6 lines · azurIt
sysfs was already mounted:
# mount sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
Quoted 12 lines
Quoted 2 lines
I have enabled all of the options you suggested and also
CONFIG_DEBUG_FS;) I will boot new kernel this night. Hope it won't degraded performance much..It's only for curiousity's sake. As you report the patch fixes the problem, it matches the theory that it's allocator latency. The script would confirm it for sure, but it's not a high priority.
Signature · 2 lines
Mel Gorman SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · azurIt
So it's really not necessary ? It would be better for us if you can go without it cos it means to run buggy kernel for one more day.
I can live without it.
Quoted 2 lines
Which kernel versions will include this fix ?
As it's a performance fix, I would guess 2.6.39 only. I don't think -stable pick up performance fixes but I could be wrong.
Signature · 9 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines
azurlt, would you please test the patch attached? Thanks.
This patch fixed the problem, i used 2.6.36.4 for testing. Do you need from me to test also other kernel versions or patches ?
Thank you very much!
______________________________________________________________
Quoted 28 lines
Od: "Changli Gao" <[email protected]>
Komu: Eric Dumazet <[email protected]>
Dátum: 07.04.2011 17:27
Predmet: Re: Regression from 2.6.36CC: "Américo Wang" <[email protected]>, "Jiri Slaby" <[email protected]>, [email protected], "Andrew Morton" <[email protected]>, [email protected], [email protected], "Jiri Slaby" <[email protected]>
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet
We had a similar memory problem in
fib_triein the past : We force asynchronize_rcu()every XXX Mbytes allocated to make sure we dont have too much ram waiting to be freed in rcu queues.I don't think there is too much memory allocated by vmalloc to free. My patch should reduce the size of the memory allocated by
vmalloc(). I think the real problem is kfree always returns the memory, whose size is aligned to 2^n pages, and more memory are used than before.Quoted 10 lines
This was done in commit
c3059477fce2d956(ipv4: Usesynchronize_rcu()duringtrie_rebalance())It was possible in
fib_triebecause we hold RTNL lock, so managing a counter was free.In fs case, we might use a
percpu_counterif we really want to limit the amount of space.
Quoted 13 lines
Quoted 2 lines
Now, I am not even sure we should care that much and could just forget about this high order pages use.
In normal cases, only a few fds are used, the ftable isn't larger than one page, so we should use kmalloc to reduce the memory cost. Maybe we should set a upper limit for
kmalloc()here. One page?Signature · 2 lines
Regards, Changli Gao([email protected])
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>